<html>
<body>
    <h1>TCP Server</h1>
</body>
<script>
    let net = require('net');
let server = net.createServer(socket => {
    socket.on('data', data =>{
        console.log('server recv data:', data);
    })
    socket.on('close', function(hadError) {
        console.log(`sock close hadError: "${hadError}"`);
    })
    socket.on('end', function() {
        console.log('sock end');
    })
    socket.on('error', function(err) {
        console.log('sock err:', err);
    })
    // 设置最大连接数
    server.maxConnections = 100;
    // 获取连接数
    server.getConnections((err, count) => {
        console.log('server count:', count);
    })
});

server.listen(10033, () => {
    console.log("server is running on 10033");
})
server.on('error', function(err) {
    console.log("server err:", err);
})
server.on('close', () => {
    console.log("server closed")
})
</script>

</html>